//
//  OtherInterface.m
//  DaJiang
//
//  Created by sally on 17/1/15.
//  Copyright © 2017年 jiniu. All rights reserved.
//

#import "OtherInterface.h"

@implementation OtherInterface

- (id)init {
  self = [super initWithPath:@"/all"];
  if (self) {
  }
  return self;
}

//选择时间接口
- (void)queryTimeWithCompletion:(completion_t)completion
                          error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/choose_time_find.json"];
  NSURL *url = self.interfaceURL;

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:nil success:netCompletion failure:netFailure];
}

//查询省级区域接口
- (void)queryLocWithCompletion:(completion_t)completion
                         error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/all"];
  NSURL *url = CREATE_REAL_URL(self.interfaceURL, @"location/get.json");

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:nil success:netCompletion failure:netFailure];
}

//查询市级区域接口
- (void)queryCityWithLoc:(NSString *)locId
              completion:(completion_t)completion
                   error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/found"];
  NSURL *url = CREATE_REAL_URL(self.interfaceURL, @"city/list.json");

  NSDictionary *parameters = @{ @"parent" : locId,
  };

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:parameters success:netCompletion failure:netFailure];
}

//查询市2级区域接口
- (void)queryCity2WithLoc:(NSString *)locId
               completion:(completion_t)completion
                    error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/found"];
  NSURL *url = CREATE_REAL_URL(self.interfaceURL, @"area/list.json");

  NSDictionary *parameters = @{ @"parent" : locId,
  };

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:parameters success:netCompletion failure:netFailure];
}

//学历列表接口
- (void)queryEducationWithCompletion:(completion_t)completion
                               error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/education_find.json"];
  NSURL *url = self.interfaceURL;

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:nil success:netCompletion failure:netFailure];
}

//年限列表接口
- (void)queryYearWithCompletion:(completion_t)completion
                          error:(error_t)error {
  self.interfaceURL = [[NSURL alloc] initWithScheme:Scheme host:[ApiBase shareInstance].host path:@"/work_year_find.json"];
  NSURL *url = self.interfaceURL;

  netCompletion_t netCompletion = ^(AFHTTPRequestOperation *operation, id responseObject) {
    NSDictionary *resultDict = responseObject;
    if (resultDict) {
      if (completion) {
        NSDictionary *resultObject = [resultDict objectForKey:DicKeyResult];
        NSInteger code = [[resultDict objectForKey:DicKeyErrorCode] integerValue];
        NSString *description = [resultDict objectForKey:DicKeyErrorMsg];
        description = description ? description : @"";
        completion(resultObject, code, description);
      }
    }
  };

  netFailure_t netFailure = ^(AFHTTPRequestOperation *option, NSError *e) {
    if (error) {
      error(e);
    }
  };

  AFHTTPRequestOperationManager *manager = [ApiBase shareInstance].shareManager;
  [manager POST:[url absoluteString] parameters:nil success:netCompletion failure:netFailure];
}

@end
